package com.think.archive.controller;

import com.think.archive.dto.SysRoleDto;
import com.think.archive.model.SysGlobalCode;
import com.think.archive.model.SysRole;
import com.think.archive.service.SysDeptService;
import com.think.archive.service.SysFuncService;
import com.think.archive.service.SysGlobalCodeService;
import com.think.archive.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("admin")
public class AdminController {

    @Autowired
    SysRoleService roleService;

    @Autowired
    SysDeptService deptService;

    @Autowired
    SysFuncService funcService;

    @Autowired
    SysGlobalCodeService globalCodeService;

    @RequestMapping("table")
    public String table(){
        return "admin/table";
    }

    @RequestMapping("user/list")
    public String userList(ModelMap map){
        map.addAttribute("mapping","user");
        map.addAttribute("titleName","用户管理");
        List<SysRoleDto> roles=roleService.selectAllRole();
        map.addAttribute("roles",roles);
        List<SysGlobalCode> globalCodes=globalCodeService.selectNextLevelGlobalCode("9901");
        map.addAttribute("globalCodes",globalCodes);
        return "admin/users";
    }

    @RequestMapping("role/list")
    public String roleList(ModelMap map,@RequestParam(value = "roleCode", required = false) String roleCode){
        map.addAttribute("mapping","role");
        map.addAttribute("titleName","角色管理");
        List<SysGlobalCode> globalCodes=globalCodeService.selectNextLevelGlobalCode("9901");
        map.addAttribute("globalCodes",globalCodes);
        map.addAttribute("roleCode",roleCode==null?"01":roleCode);
        map.addAttribute("roleTree",roleService.findRoleTree(roleCode==null?"01":roleCode).toJSONString());
        return "admin/roles";
    }

    @RequestMapping("dept/list")
    public String deptList(ModelMap map,@RequestParam(value = "deptCode", required = false) String deptCode){
        map.addAttribute("mapping","dept");
        map.addAttribute("titleName","部门管理");
        List<SysGlobalCode> globalCodes=globalCodeService.selectNextLevelGlobalCode("9901");
        map.addAttribute("globalCodes",globalCodes);
        map.addAttribute("deptCode",deptCode==null?"01":deptCode);
        map.addAttribute("deptTree",deptService.findDeptTree(deptCode==null?"01":deptCode).toJSONString());
        return "admin/depts";
    }

    @RequestMapping("func/list")
    public String funcList(ModelMap map,@RequestParam(value = "funcCode", required = false) String funcCode){
        map.addAttribute("mapping","func");
        map.addAttribute("titleName","功能管理");
        List<SysGlobalCode> globalCodes=globalCodeService.selectNextLevelGlobalCode("9901");
        map.addAttribute("globalCodes",globalCodes);
        map.addAttribute("funcCode",funcCode==null?"01":funcCode);
        map.addAttribute("funcTree",funcService.findFuncTree(funcCode==null?"01":funcCode).toJSONString());
        return "admin/funcs";
    }


    @RequestMapping("log/list")
    public String logList(ModelMap map){
        map.addAttribute("mapping","log");
        map.addAttribute("titleName","日志管理");
        return "admin/logs";
    }

    @RequestMapping("archive/add")
    public String archiveAdd(ModelMap map){
        map.addAttribute("mapping","archive");
        map.addAttribute("titleName","档案上传");
        return "admin/archive/add";
    }

    @RequestMapping("archive/scan")
    public String archiveScan(ModelMap map){
        map.addAttribute("mapping","scan");
        map.addAttribute("titleName","档案扫描");
        return "admin/archive/scan";
    }

    @RequestMapping("archive/list")
    public String archiveList(ModelMap map){
        map.addAttribute("mapping","archives");
        map.addAttribute("titleName","档案查询");
        return "admin/archive/list";
    }



}
